feat: add npm OIDC trusted publishing support#561
Closed
GarthDB wants to merge 2 commits intochangesets:mainfrom
Closed
feat: add npm OIDC trusted publishing support#561GarthDB wants to merge 2 commits intochangesets:mainfrom
GarthDB wants to merge 2 commits intochangesets:mainfrom
Conversation
Add support for npm's OIDC trusted publishing, eliminating the need for long-lived NPM_TOKEN secrets. This provides better security through cryptographic provenance attestation and short-lived credentials. Changes: - Add `oidcAuth` boolean input parameter (default: false) - Implement OIDC environment validation: - Check npm version >= 11.5.1 - Verify id-token: write permission - Detect conflicting NPM_TOKEN - Early authentication validation before changeset operations - Skip .npmrc creation in OIDC mode (npm CLI auto-detects OIDC) - Explicit environment variable passing for compatibility with toolchains like proto shims and moon that start fresh shells - Maintain full backward compatibility with NPM_TOKEN authentication Tests: - 9 unit tests for OIDC validation - 13 integration tests for authentication setup - Full backward compatibility test coverage - All tests passing (30 total) Documentation: - Comprehensive OIDC setup guide with prerequisites - Migration instructions from NPM_TOKEN to OIDC - Clear explanation of benefits and provenance attestation - Example workflows for both authentication methods Resolves: changesets#515
|
Author
|
After some further tests, I made a better pr with #562 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for npm's OIDC-based trusted publishing, which lets you publish packages without managing long-lived NPM tokens.
What this addresses
Closes #542 and helps with #515 by enabling OIDC in the current workflow model. Related to #545 but takes a more comprehensive approach.
Changes
Added a new
oidcAuthinput parameter (defaults tofalsefor backward compatibility). When enabled, the action validates your OIDC environment before trying to publish:id-token: writepermission is setNPM_TOKENset (conflicting auth)The implementation explicitly passes OIDC environment variables to the publish command. This is necessary because some toolchains spawn fresh shell processes, and we need to ensure the OIDC tokens reach npm even through those layers.
Testing
I've been testing this in production at Adobe (spectrum-design-data repo) and added comprehensive test coverage:
All 30 tests pass locally.
How to use it
You'll also need to configure trusted publishing on npmjs.com for your packages (one-time setup).
Why this approach vs PR #545
PR #545 just prevents writing
undefinedto.npmrc, but doesn't validate the environment or provide any feedback when things are misconfigured. This implementation validates upfront and gives you clear error messages if something's wrong, which saves a lot of debugging time.Backward compatibility
Fully backward compatible - existing workflows using
NPM_TOKENcontinue to work unchanged. OIDC is opt-in via the new parameter.